Android获取wifi的IP 子网掩码 网关 dns等信息
(byte)(0xff (hostAddress 16)),(byte)(0xff (hostAddress 24)) };try {return InetAddress.getByAddress(addressBytes);} catch (UnknownHostException e) {throw new AssertionError();}} ,public class MainActivity extends Activity {private WifiManager my_wifiManager;private WifiInfo wifiInfo;private DhcpInfo dhcpInfo;private TextView tvResult;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);my_wifiManager = ((WifiManager) getSystemService(wifi));dhcpInfo = my_wifiManager.getDhcpInfo();wifiInfo = my_wifiManager.getConnectionInfo();tvResult = (TextView) findViewById(R.id.tvResult);}@Overrideprotected void onResume() {super.onResume();StringBuilder sb = new StringBuilder();sb.append(网络信息:);sb.append(\nipAddress: + intToIp(dhcpInfo.ipAddress));sb.append(\nnetmask: + intToIp(dhcpInfo.netmask));sb.append(\ngateway: + intToIp(dhcpInfo.gateway));sb.append(\nserverAddress: + intToIp(dhcpInfo.serverAddress));sb.append(\ndns1: + intToIp(dhcpInfo.dns1));sb.append(\ndns2: + intToIp(dhcpInfo.dns2));sb.append(\n);System.out.println(intToIp(dhcpInfo.ipAddress));System.out.println(intToIp(dhcpInfo.netmask));System.out.println(intToIp(dhcpInfo.gateway));System.out.println(intToIp(dhcpInfo.serverAddress));System.out.println(intToIp(dhcpInfo.dns1));System.out.println(intToIp(dhcpInfo.dns2));System.out.println(dhcpInfo.leaseDuration);sb.append(Wifi信息:);sb.append(\nIpAddress: + intToIp(wifiInfo.getIpAddress()));sb.append(\nMacAddress: + wifiInfo.getMacAddress());tvResult.setText(sb.toString());}private String intToIp(int paramInt) {return (paramInt 0xFF) + . + (0xFF paramInt 8) + . + (0xFF paramInt 16) + .+ (0xFF paramInt 24);}} 效果如下: 备注: android.net.NetworkUtils /*** Convert a IPv4 address from an integer to an InetAddress.* @param hostAddress an int corresponding to the IPv4 address in network byte order*/public static InetAddress intToInetAddress(int hostAddress) {byte[] addressBytes = { (byte)(0xff hostAddress),(byte)(0xff (hostAddress 8)),。
相关热词:
本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!
本文地址: https://v30.fanwenzhu.com/server/dns/11958.shtml
相关文章
热门TAG
win10 ecshop 主机 阿里云 解决 配置 C# C++ 解析 SQL语句 命令 Go语言 方法 CSS3 HTML5 CSS win7 MSSQL 服务器配置 IIS7.5 IIS7 IIS6 IIS CentOS 7 Linux oracle数据库 oracle phpcms discuz discuz教程最新文章
-
这样当下一次还有另外一
时间:2021-01-15
-
在常规设置中点选使用下
时间:2021-01-15
-
总结DNS处事器负载平衡设
时间:2021-01-15
-
DNS缓存中毒进攻
时间:2021-01-15
-
结果就是访问不到界面
时间:2021-01-15
-
linux下DNS服务的搭建
时间:2021-01-08
-
DNS详解(二)
时间:2021-01-08
-
Ubuntu14.04.2LTS配置DNSserver
时间:2021-01-08
热门文章
-
如何知道是否遭遇了DNS污染
时间:2020-12-22
-
linux下DNS服务的搭建
时间:2021-01-08
-
总结DNS服务器负载均衡配置的原理及优缺
时间:2020-12-22
-
GoDaddy设置域名服务器(NS)最新教程
时间:2020-12-22
-
Win7找不到服务器或DNS错误解决方法
时间:2020-12-29
-
快速解决DNS服务器未响应的四个小妙招
时间:2021-01-08
-
图文详解添加DNS服务器的操作步骤
时间:2020-12-25
-
CDN使用了哪些DNS技术?
时间:2020-12-22
-
DNS缓存中毒攻击
时间:2020-12-22
-
Android获取wifi的IP 子网掩码 网关 dns等信息
时间:2021-01-08
